﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site/HeThongSpa.Master" AutoEventWireup="true" CodeBehind="DanhMucPhong.aspx.cs" Inherits="HeThongSpa.QuanTriHeThong.DanhMuc.DanhMucPhong" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Danh mục phòng
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeaderContent" runat="server">
    <h1 style="font-weight: bold;">Danh mục phòng</h1>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="MainContent" runat="server">
    <div class="box">
        <div class="box-header with-border">
            <h3 class="box-title" style="font-size: 12px; color: #E08E0B;">Lưu ý: Mã phòng sẽ được tự động bỏ dấu, khoảng trắng và viết hoa toàn bộ.</h3>
            <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse">
                    <i class="fa fa-minus"></i>
                </button>
            </div>
        </div>
        <div class="box-body" style="padding-bottom: 0;">
            <div class="row">
                <div class="col-xs-12 col-sm-3 col-md-3">
                    <div class="form-group form-group-sm">
                        <label>
                            Mã phòng&nbsp;<span style="color: #D73925;">*</span>
                        </label>
                        <asp:TextBox ID="txtMaPhong" runat="server" CssClass="form-control" placeholder="Mã phòng" MaxLength="50"></asp:TextBox>
                    </div>
                </div>
                <div class="col-xs-12 col-sm-4 col-md-4">
                    <div class="form-group form-group-sm">
                        <label>
                            Tên phòng&nbsp;<span style="color: #D73925;">*</span>
                        </label>
                        <asp:TextBox ID="txtTenPhong" runat="server" CssClass="form-control" placeholder="Tên phòng" MaxLength="200"></asp:TextBox>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-footer">
            <asp:Button ID="btnLuu" CssClass="btn btn-primary btn-sm btn-flat" runat="server" Text="Lưu"
                OnClientClick=" validationform() " OnClick="btnLuu_Click" />
            <asp:Button ID="btnXoa" CssClass="btn btn-danger btn-sm btn-flat" runat="server" Text="Xóa"
                OnClientClick=" return btnXoa_showconfirm(this.id); " OnClick="btnXoa_Click" />
            <asp:Button ID="btnTimKiem" CssClass="btn btn-success btn-sm btn-flat" runat="server" Text="Tìm kiếm"
                OnClientClick=" $('#form_Main').validate().cancelSubmit = true; " OnClick="btnTimKiem_Click" />
            <asp:Button ID="btnNhapLai" CssClass="btn btn-warning btn-sm btn-flat" runat="server" Text="Nhập lại"
                OnClientClick=" $('#form_Main').validate().cancelSubmit = true; " OnClick="btnNhapLai_Click" />
        </div>
    </div>
    <div class="box">
        <div class="box-header with-border">
            <h3 class="box-title"></h3>
            <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse">
                    <i class="fa fa-minus"></i>
                </button>
            </div>
        </div>
        <div class="box-body" style="padding-bottom: 0;">
            <div class="table-responsive">
                <asp:GridView ID="gvDanhMuc" runat="server" AutoGenerateColumns="False" Width="100%" CssClass="table table-bordered table-condensed"
                    OnRowCreated="gvDanhMuc_OnRowCreated" DataKeyNames="MaPhong" ShowHeaderWhenEmpty="True">
                    <EmptyDataTemplate>
                        <div class="row text-center">
                            <label>Không có dữ hiện hiển thị</label>
                        </div>
                    </EmptyDataTemplate>
                    <Columns>
                        <asp:TemplateField>
                            <HeaderTemplate>
                                <asp:CheckBox ID="checkall_id" runat="server" ToolTip="Chọn tất cả" onclick="javascript:checkallClick(this);" />
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:CheckBox ID="check_id" runat="server" />
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" Width="5%" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="RowNumber" HeaderText="STT">
                            <ItemStyle HorizontalAlign="Center" Width="10%"></ItemStyle>
                        </asp:BoundField>
                        <asp:BoundField DataField="MaPhong" HeaderText="Mã phòng"></asp:BoundField>
                        <asp:BoundField DataField="TenPhong" HeaderText="Tên phòng"></asp:BoundField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:LinkButton ID="btnSua" runat="server" ToolTip="Sửa" CssClass="btn btn-success btn-xs btn-flat"
                                    CommandArgument='<%# Eval("MaPhong") %>' OnClick="btnSua_Click" OnClientClick=" $('#form_Main').validate().cancelSubmit = true; ">
                                    <i class="glyphicon glyphicon-edit"></i>
                                </asp:LinkButton>
                                <asp:LinkButton ID="btnDelete" runat="server" ToolTip="Xóa" CssClass="btn btn-danger btn-xs btn-flat"
                                    CommandArgument='<%# Eval("MaPhong") %>' OnClick="btnDelete_Click" OnClientClick=" return showconfirm(this.id); ">
                                    <i class="glyphicon glyphicon-trash"></i>
                                </asp:LinkButton>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" Width="15%" />
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
            </div>
            <div class="row">
                <div class="col-xs-12 col-sm-12 col-md-12">
                    <asp:DataList RepeatDirection="Horizontal" runat="server" ID="dlPager" OnItemCommand="dlPager_ItemCommand"
                        CssClass="tbPage">
                        <ItemTemplate>
                            <asp:LinkButton Enabled='<%#Eval("Enabled") %>' runat="server" ID="lnkPageNo" Text='<%#Eval("Text") %>'
                                CommandArgument='<%#Eval("Value") %>' CommandName="PageNo">
                            </asp:LinkButton>
                        </ItemTemplate>
                    </asp:DataList>
                </div>
            </div>
        </div>
    </div>
    <asp:HiddenField ID="hfTimKiem" runat="server" Value="false" />
    <asp:HiddenField ID="hfPageIndex" runat="server" Value="1" />
    <script type="text/javascript">
        var TotalChkBx;
        var Counter;

        $(function () {
            $("#li_danhmuc").addClass("active");
            $("#li_danhmuc_danhmucphong").addClass("active");
            TotalChkBx = parseInt("<%= gvDanhMuc.Rows.Count %>");
            Counter = 0;
        });

        function validationform() {
            $("#<%= txtMaPhong.ClientID %>").rules("add", {
                required: true,
                messages: {
                    required: errempty
                }
            });
            $("#<%= txtTenPhong.ClientID %>").rules("add", {
                required: true,
                messages: {
                    required: errempty
                }
            });
        }

        function checkallClick(checkBox) {
            var targetBaseControl = document.getElementById("<%= gvDanhMuc.ClientID %>");
            var targetChildControl = "check_id";
            var inputs = targetBaseControl.getElementsByTagName("input");
            for (var n = 0; n < inputs.length; ++n)
                if (inputs[n].type === "checkbox" && inputs[n].id.indexOf(targetChildControl, 0) >= 0)
                    inputs[n].checked = checkBox.checked;
            Counter = checkBox.checked ? TotalChkBx : 0;
        }

        function checkClick(checkBox, hCheckBox) {
            var headerCheckBox = document.getElementById(hCheckBox);
            if (checkBox.checked && Counter < TotalChkBx) Counter++;
            else if (Counter > 0) Counter--;
            if (Counter < TotalChkBx) headerCheckBox.checked = false;
            else if (Counter === TotalChkBx) headerCheckBox.checked = true;
        }

        var confirmed = false;

        function btnXoa_showconfirm(controlId) {
            if (Counter === 0) {
                bootbox.alert("Bạn cần chọn bản ghi trước khi xóa!");
            } else {
                if (confirmed) {
                    return true;
                }
                bootbox.confirm("Bạn có chắc chắn xóa?", function (result) {
                    if (result) {
                        if (controlId != null) {
                            var controlToClick = document.getElementById(controlId);
                            if (controlToClick != null) {
                                confirmed = true;
                                $("#form_Main").validate().cancelSubmit = true;
                                controlToClick.click();
                                confirmed = false;
                            }
                        }
                    }
                });
            }
            return false;
        }

        function showconfirm(controlId) {
            if (confirmed) return true;
            bootbox.confirm("Bạn có chắc chắn xóa?", function (result) {
                if (result) {
                    if (controlId != null) {
                        var controlToClick = document.getElementById(controlId);
                        if (controlToClick != null) {
                            confirmed = true;
                            $("#form_Main").validate().cancelSubmit = true;
                            controlToClick.click();
                            confirmed = false;
                        }
                    }
                }
            });
            return false;
        }
    </script>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="FormContent" runat="server">
</asp:Content>
